package slap.paradigm;

import java.util.HashMap;
import java.util.Map;

public class ModelsContext {

	public Map<String, Object> data = new HashMap<String, Object>();

	public void put(String key, Object value) {
		if (value == null) {
			data.remove(key);
		} else {
			data.put(key, value);
		}
	}
	
	public void put(Model model) {
		put(model.name, model.value);
	}
	
	public <T> T get(String key, Class<T> clazz) {
		return (T) data.get(key);
	}

	public String get(String key) {
		return get(key, String.class);
	}

	public boolean remove(String key) {
		return data.remove(key) != null;
	}

	public void remove(String... keys) {
		for (String key : keys) {
			remove(key);
		}
	}

	public void clear() {
		data.clear();
	}

	public boolean contains(String key) {
		return data.containsKey(key);
	}
}